<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>系统日志</title>
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/assets/module/admin.css?v=315"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #tableTbImg + .layui-table-view .layui-table-body tbody > tr > td {
            padding: 0;
        }

        #tableTbImg + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
            height: 60px;
            line-height: 60px;
        }

        .tdImg {
            width: 50px;
            height: 50px;
            max-width: none;
            cursor: zoom-in;
        }

    </style>
</head>
<body>

<!-- 页面加载loading -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">订单ID：</label>
                        <div class="layui-input-inline mr0">
                            <input type="text" name="orderId" id="orderId" placeholder="请输入订单号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">收货姓名：</label>
                        <div class="layui-input-inline mr0">
                            <input type="text" name="username"id="username" placeholder="请输入收货人姓名" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">支付方式：</label>
                        <div class="layui-input-inline">
                            <select name="pay" id="pay">
                                <option value="">支付方式</option>
                                <option value="1">支付宝</option>
                                <option value="2">微信</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">订单状态：</label>
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="">订单状态</option>
                                <option value="1">待支付</option>
                                <option value="2">已支付</option>
                                <option value="3">待收货</option>
                                <option value="4">已收货</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">订单时间：</label>
                        <div class="layui-input-inline mr0">
                            <input class="layui-input date-icon" id="timearea" placeholder="请选择查询时间段" type="text" autocomplete="off">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchLog" data-type="reload" lay-submit >
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="order" lay-filter="tableOrder"></table>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <shiro:hasPermission name="order:delete">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </shiro:hasPermission>
    <shiro:lacksPermission name="order:delete">
        <span class="layui-btn layui-btn-danger layui-btn-xs">无权限</span>
    </shiro:lacksPermission>
</script>
<script type="text/html" id="toolbarDemo">
    <shiro:hasPermission name="order:delete">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="delete">删除选中</button>
        </div>
    </shiro:hasPermission>
    <shiro:lacksPermission name="order:delete">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-danger" disabled>无权限</button>
        </div>
    </shiro:lacksPermission>
</script>
<script type="text/javascript" src="/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/assets/js/common.js?v=315"></script>
<script>
    layui.use(['laydate','form','table','notice'],function () {
        var laydate=layui.laydate,
        form=layui.form,
        table=layui.table,
         notice=layui.notice;
        //时间选择器
        laydate.render({
            elem: '#timearea'
            , range: true
            ,trigger: 'click' //采用click弹出
        });

        var talbeIns=table.render({
            elem: '#order'
            ,url:'/order/list'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['print', 'exports', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '刷新'
                ,layEvent: 'reset'
                ,icon: 'layui-icon-refresh'
            }]
            ,cols: [
                [
                    {type: 'checkbox'}
                    ,{field:'orderId',  title: '订单编号', align:'center',width:160}
                    ,{field:'name',  title: '收货人姓名', align:'center',width:130}
                    ,{field:'telephone',  title: '收货人电话', align:'center',width:120}
                    ,{field:'orderTitle',  title: '商品标题', align:'center',width:100}
                    ,{field:'orderImage', align:'center',templet:function(d){
                        var url=d.orderImage;
                        return '<img src="' + url + '" class="tdImg" tb-img/>';
                    }, title: '商品图片',width:90}
                    ,{field:'orderPrice', title: '商品单价', sort: true, align:'center',width:90}
                    ,{field:'orderCount', title: '购买数量', sort: true, align:'center'}
                    ,{field:'orderSubTotal', title: '应付金额', sort: true, align:'center',width:90}
                    ,{field:'orderShouhStr', title: '订单状态', align:'center',width:80}
                    ,{field:'orderIspayStr', title: '是否支付', align:'center',width:80}
                    ,{field:'orderTypeStr', title: '支付方式', align:'center',width:80}
                    ,{field:'orderTime', title: '创建时间', sort: true, align:'center',width:200}
                    ,{fixed: 'right', title:'操作', toolbar: '#barDemo',align:'center',width:100}
                ]
            ]
            ,page: true
            ,limit:10
            , limits: [ 5, 10, 15, 20,25]
            , loading: true
        });

        //监听行工具事件
        table.on('tool(tableOrder)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('确定删除此数据？',{icon:3, title:'提示信息',skin:"layui-layer-admin"},function(index){
                    $.get('/order/delete/'+obj.data.id,function(data){
                        if (data.code==200){
                            talbeIns.reload();
                            layer.close(index);
                            notice.msg("删除订单成功",{icon:1,timeout:2000,animateInside:true,audio:'1'});
                        } else{
                            notice.msg(data.message,{icon:2,timeout:2000,animateInside:true,audio:'1'});
                        }
                    });
                });
            }
        });
        //头工具栏事件
        table.on('toolbar(tableOrder)', function(obj) {
            if (obj.event === 'delete') {
                var checkStatus = table.checkStatus(obj.config.id);
                if (!checkStatus.data.length) {
                    notice.msg("请选择要删除的数据！！",{icon:5,timeout:2000,animateInside:true,audio:'1'});
                } else {
                    layer.confirm('确定删除多条数据？', {icon: 3, title: '提示信息',skin:"layui-layer-admin"}, function (index) {
                        var logIds = [];
                        layui.each(checkStatus.data, function (key, item) {
                            logIds.push(item.id);
                        });
                        $.get('/order/delete/' + logIds, function (data) {
                            if (data.code === 200) {
                                talbeIns.reload();
                                layer.close(index);
                                notice.msg("删除多条订单成功",{icon:1,timeout:2000,animateInside:true,audio:'1'});
                            } else {
                                notice.msg(data.message,{icon:1,timeout:2000,animateInside:true,audio:'1'});
                            }
                        });
                    });
                }
            }
            if(obj.event==='reset'){
                talbeIns.reload();
            }
        });

        //表单刷新
        var $ = layui.$, active = {
            reload: function(){
                var timeArea = $("#timearea").val();
                var orderId=$("#orderId").val();
                var username=$("#username").val();
                var pay=$("#pay").val();
                var status=$("#status").val();
                var startTime = "";
                var endTime = "";
                if (timeArea) {
                    startTime = timeArea.split(" - ")[0];//开始时间
                    endTime = timeArea.split(" - ")[1];//结束时间
                }
                //执行重载
                table.reload('order', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        orderId:orderId,
                        username:username,
                        pay:pay,
                        status:status,
                        startTime:startTime,
                        endTime:endTime
                    }
                }, 'data');
            }
        };

        // 点击图片放大
        $(document).off('click.tbImg').on('click.tbImg', '[tb-img]', function () {
            layer.photos(
                {
                    photos: {
                        data: [{src: $(this).attr('src')}]
                    },
                    shade: .1,
                    closeBtn: true
                }
            );
        });

        //点击搜索按钮
        form.on("submit(formSubSearchLog)",function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        })

    })
</script>
</body>
</html>